@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">
    <div class="layui-form-item">
        <label class="layui-form-label">用户搜索</label>
        <div class="layui-input-inline">
            <input type="text" id="user_id" autocomplete="off" placeholder="手机号、昵称、上级用户id" class="layui-input">
        </div>
        <div class="layui-input-inline">
{{--            <select name="vip_level" id="vip_level" lay-filter = "province">--}}
{{--                <option value="">请选择会员身份</option>--}}
{{--                <option value="0">游客</option>--}}
{{--                <option value="1">银袖会员</option>--}}
{{--                <option value="2" >金袖会员</option>--}}
{{--                <option value="3" >华袖会员</option>--}}
{{--            </select>--}}
        </div>


        <button class="layui-btn" data-type="reload">搜索</button>
    </div>
</div>
<div class="layui-btn-container">
</div>

<table class="layui-hide" id="think-table" lay-filter="think-table"></table>


<script id="barDemo" type="text/html">
         <a class="layui-btn layui-btn-xs" lay-event="chongzhi">余额充值</a>
         <a class="layui-btn layui-btn-xs" lay-event="user_edit">用户编辑</a>
         <a class="layui-btn layui-btn-xs" lay-event="set_shop_user">供应商设置</a>
         @{{#  if(d.is_hehuo ==0){ }}
{{--            <a class="layui-btn layui-btn-xs" lay-event="set_hehuo">设为合伙人</a>--}}
         @{{#  }else{ }}
{{--            <a class="layui-btn layui-btn-xs" lay-event="set_hehuo">取消合伙人</a>--}}

         @{{#  } }}

{{--    <a class="layui-btn layui-btn-xs" lay-event="money">添加余额</a>--}}
{{--    <a class="layui-btn layui-btn-xs" lay-event="fengjin">封禁</a>--}}

</script>
<script>
    function money_xiaofei_ajax(user_id,money,index){

    }
</script>
<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.users.user')}}?type=1", [
            {field: 'user_id', title: 'ID', width:80, sort: true,fixed: 'left'}
            ,{field: 'nickname',title:'用户昵称'}
            ,{field: 'user_phone',title:'手机号'}
            ,{field: 'money',title:'余额'}
            ,{field: 'is_hehuo',title:'上级用户',templet:function (d){
                    if(d['spread_info'] == null){
                        return '暂无用户';
                    }
                    return  d['spread_info']['user_id'] + '-'+d['spread_info']['nickname'];
            }}
            ,{field: 'is_hehuo',title:'是否合伙人',templet:function (d){
                    let arr = ['否','是'];
                    return arr[d['is_hehuo']]
                }}
            ,{field: 'is_hehuo',title:'会员',templet:function (d){
                    let arr = ['普通','银袖会员','金袖会员','华袖会员'];
                    return arr[d['vip_level']]
                }}
            ,{field: 'created_at',title:'注册时间',templet:function (d){
                console.log(d['created_at']);
                return layui.util.toDateString(parseInt(d['created_at'])*1000,'yyyy-MM-dd HH:mm:ss')
           }}
            ,{fixed: 'right',title:'操作',width: 380, align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event == 'set_shop_user'){
                UI.openLayer("{{route('admin.users.set_shop_user')}}?user_id="+data['user_id']);
            }else if(obj.event == 'user_edit'){
                UI.openLayer("{{route('admin.users.user_edit')}}?user_id="+data['user_id']);
            }else if(obj.event == 'chongzhi'){
                UI.openLayer("{{route('admin.users.chongzhi')}}?user_id="+data['user_id']);
            }else if(obj.event == 'set_hehuo'){
                UI.delete(data['user_id'],function (res){
                    table.reload('think-table');
                },'{{route('admin.users.set_hehuo')}}','是否设置/取消合伙人?')
            }
        });
        let $ = layui.$, active = {

            reload:function (){
                let user_id = $('#user_id');
                let vip_level = $('#vip_level');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'search_key':user_id.val(),
                        'vip_level':vip_level.val()
                    }
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
